<?php

declare (strict_types=1);

namespace App\Model;

use Hyperf\Database\Model\SoftDeletes;
use Hyperf\DbConnection\Model\Model;

/**
 * @property \Carbon\Carbon $created_at
 * @property int $id
 * @property string $nickname
 * @property string $password
 * @property \Carbon\Carbon $updated_at
 */
class User extends Model
{
    use SoftDeletes;
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'users';
    /**
     * The connection name for the model.
     *
     * @var string
     */
    protected $connection = 'default';
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['avatar' => 'array'];

    protected $guarded = [];

    public function roles()
    {
        return $this->belongsToMany(Role::class, 'user_role');
    }

    public function chatRooms()
    {
        return $this->belongsToMany(ChatRoom::class,
            'user_chat_room',
            'user_id',
            'chat_room_id'
        );
    }
}
